#ifndef __FILEWATCHER__H__
#define __FILEWATCHER__H__

#include <QFileSystemWatcher>
#include <QObject>

class FileWatcher : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged FINAL)
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)

public:
    explicit FileWatcher(QObject *parent = nullptr);

    QString filePath() const;
    void setFilePath(const QString &newFilePath);

    Q_INVOKABLE void startWatching();
    Q_INVOKABLE void stopWatching();

    bool enabled();
    void setEnabled(bool enabled);

signals:
    void fileChanged(const QString &filePath);
    void filePathChanged();

private slots:
    void onFileChanged(const QString &path);

private:
    QFileSystemWatcher *m_watcher;
    QString m_filePath;
    bool m_enabled;
};

#endif  //!__FILEWATCHER__H__
